﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Data;
using System.Data.SqlClient;
using VisaCRM.Modules.Admin.Model;
using VisaCRM.Common.Helper;

namespace VisaCRM.Modules.Admin.Gateway
{
    class BranchGateway
    {
        internal ObservableCollection<Branch> GetAllBranch()
        {
            ObservableCollection<Branch> allbranch = new ObservableCollection<Branch>();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchBranchList());
            if (dt.Rows.Count <= 0)
            {
                return allbranch;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                allbranch.Add(new Branch()
                {
                    BranchID = Convert.ToInt32(dataRow["Branch_ID"].ToString()),
                    BranchName = dataRow["Branch_Name"].ToString()

                });
            }
            return allbranch;
        }

        internal Branch GetCurrentbranch(int id)
        {
            Branch Branch = new Branch();
            DataTable dt = new DataTable();
            dt = DBHelper.GetDataTable(QueryProvider.MakeSQLQueryToFetchCurrentBranch(id));
            if (dt.Rows.Count <= 0)
            {
                return Branch;
            }
            foreach (DataRow dataRow in (InternalDataCollectionBase)dt.Rows)
            {
                Branch.BranchID = Convert.ToInt32(dataRow["Branch_ID"].ToString());
                Branch.BranchName = dataRow["Branch_Name"].ToString();
            }
            return Branch;
        }
    }
}
